package io.renren.modules.member.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.member.dao.TStoreMemberDao;
import io.renren.modules.member.entity.vo.MemberVo;
import io.renren.modules.member.entity.TStoreMemberEntity;
import io.renren.modules.member.service.TStoreMemberService;
import io.renren.modules.store.entity.vo.FoodDiscountVo;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;


@Service("tStoreMemberService")
public class TStoreMemberServiceImpl extends ServiceImpl<TStoreMemberDao, TStoreMemberEntity> implements TStoreMemberService {

    @Autowired
    private TStoreMemberDao tStoreMemberDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TStoreMemberEntity> page = this.page(
                new Query<TStoreMemberEntity>().getPage(params),
                new QueryWrapper<TStoreMemberEntity>()
                        .eq(params.get("sellerId") != null,"seller_id",params.get("sellerId"))
                        .eq(params.get("status") != null,"status",params.get("status"))
                        .eq(params.get("memberTypeId")!=null,"member_type_id",params.get("memberTypeId"))
                        .eq(!params.get("key").equals(""),"member_card_no",params.get("key"))
                        .or()
                        .eq(!params.get("key").equals(""),"id_card",params.get("key"))
                        .or()
                        .eq(!params.get("key").equals(""),"tel",params.get("key"))
        );

        return new PageUtils(page);
    }

    @Override
    public Page<MemberVo> listMember(Map<String, Object> params) {
        Page<FoodDiscountVo> page = new Page<FoodDiscountVo>
                (Long.parseLong((String) params.get("current")),Long.parseLong((String) params.get("size")));
        return tStoreMemberDao.listMember(page,params);
    }

}